#!/bin/sh
#
# mindist: create minimum distribution for running cputil
#
# Copyright (C) 2016 Matthew R. Wette
# 
# Copying and distribution of this file, with or without modification,
# are permitted in any medium without royalty provided the copyright
# notice and this notice are preserved.  This file is offered as-is,
# without any warranty.

prefix=@prefix@
srcdist=..

if [ $# -ne 2 ]; then
  echo "usage: mindist <destdir> <pkglibdir>"
  exit 1
fi
destdir=$1
pkglibdir=$2

dst=$destdir/$prefix

rm -f $dst/bin/callgrind*
rm -f $dst/bin/cg_*
rm -f $dst/bin/ms_print
rm -f $dst/bin/valgrind-di-server
rm -f $dst/bin/valgrind-listener
rm -f $dst/bin/vgdb
if [ -f $dst/bin/valgrind ]; then
  mv $dst/bin/valgrind $destdir/$pkglibdir/valgrind
fi
#
if [ -f $dst/include/valgrind/libvex_ir.h ]; then
  cp $dst/include/valgrind/libvex_ir.h $destdir/$pkglibdir/
fi
if [ -f $dst/include/valgrind/cputil.h ]; then
   mv $dst/include/valgrind/cputil.h $dst/
fi
rm -rf $dst/include
mkdir -p $dst/include
if [ -f $dst/cputil.h ]; then
  mv $dst/cputil.h $dst/include/
fi
rm -rf $destdir/$prefix/share
rm -rf $destdir/$prefix/lib/pkgconfig
#
rm -rf $destdir/$pkglibdir/vgpreload_memcheck*
rm -rf $destdir/$pkglibdir/vgpreload_massif*
rm -rf $destdir/$pkglibdir/vgpreload_exp*
rm -rf $destdir/$pkglibdir/vgpreload_drd*
rm -rf $destdir/$pkglibdir/vgpreload_helgrind*
#
rm  -f $destdir/$pkglibdir/s390*
rm  -f $destdir/$pkglibdir/power*
rm  -f $destdir/$pkglibdir/mips*
rm  -f $destdir/$pkglibdir/arm*
#
rm -rf $destdir/$pkglibdir/none*
rm -rf $destdir/$pkglibdir/memcheck*
rm -rf $destdir/$pkglibdir/massif*
rm -rf $destdir/$pkglibdir/getoff*
rm -rf $destdir/$pkglibdir/helgrind*
rm -rf $destdir/$pkglibdir/lackey*
rm -rf $destdir/$pkglibdir/exp*
rm -rf $destdir/$pkglibdir/drd*
rm -rf $destdir/$pkglibdir/cachegrind*
rm -rf $destdir/$pkglibdir/callgrind*
#
rm  -f $destdir/$pkglibdir/*.xml
rm  -f $destdir/$pkglibdir/*.a
rm  -f $destdir/$pkglibdir/default.supp
#

echo "#!/bin/sh" >$dst/bin/cputil
echo "VALGRIND_LIB=$pkglibdir" >>$dst/bin/cputil
echo "#export VALGRIND_LIB" >>$dst/bin/cputil
echo "\$VALGRIND_LIB/valgrind -q" '--tool=cputil "$@"' >>$dst/bin/cputil
chmod +x $dst/bin/cputil

# --- last line of mindist ---
